package cn.bd13.swagger.service.imp;

import cn.bd13.swagger.dao.AdminDao;
import cn.bd13.swagger.entity.Admin;
import cn.bd13.swagger.entity.Menu;
import cn.bd13.swagger.entity.MenuVo;
import cn.bd13.swagger.entity.User;
import cn.bd13.swagger.service.AdminService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName：AdminServiceimp
 * Package:cn.bd13.swagger.service.imp
 * Description:
 *
 * @Date:2020/5/18 15:42
 * @Author:zhangqiang@kgc.cn
 */
@Service
public class AdminServiceimp implements AdminService {

    @Resource
    private AdminDao adminDao;

    @Override
    public Admin getAdminPhone(String adminPhone) {
        return adminDao.getAdminPhone(adminPhone);
    }

    @Override
    public List<Admin> getAllAdmin() {
        return adminDao.getAllAdmin();
    }

    @Override
    public List<MenuVo> getMenuByAtype(int adminType) throws Exception{
        //首先获取这个权限的一级目录
        List<MenuVo> menuVoList=adminDao.getFirstLevelMenus(adminType);
        //循环，通过这个权限，以及当前一级目录的id，获取对应的二级目录
        for (MenuVo vo:menuVoList){
            List<Menu> menus=adminDao.getSecondLevelMenus(adminType,vo.getMenuid());
            vo.setChildren(menus);
        }
        //并将二级目录的集合，存入一级目录的对象children属性中

        return menuVoList;
    }
}
